<template>
  <view class="scanCode">
    <view class="header_btn">
      <view class=""> 物品扫码 </view>
      <view class="gray"> 核实数量 </view>
    </view>
    <view class="main"
      >{{ proName }} <br />{{ proColor }}<br />{{ proSize }}<br />{{ proPrice }}
    </view>

    <view class="footer_btn">
      <view class="" @tap="scan"> 扫一扫 </view>
      <view class="" @tap="comfir"> 确定 </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      // 颜色
      proColor: "",
      // 尺寸
      proSize: "",
      // 货号
      proName: "",
      // 单价
      proPrice: "",
      // 数量
      proNum: "",
      // 金额
      proAmt: "",
      // 备注
      remark: "",
      // 类型
      type: "",
      type1: "",
    };
  },
  methods: {
    scan() {
      let that = this;
      uni.scanCode({
        scanType: ["barCode"],
        success: function (res) {
          // console.log("条码类型:" + res.scanType);
          console.log("条码内容:" + res.result);
          // this.msg = res.result;
          that.$api
            .itemByScanApi({ data: { mid: that.mid, proId: res.result } })
            .then((res) => {
              console.log("res", res);
              if (res.code == 200) {
                that.proColor = res.result.proColor;
                that.proSize = res.result.proSize;
                that.proName = res.result.proName;
                that.proPrice = res.result.proPrice;
                that.proNum = res.result.proNum;
                that.proAmt = res.result.proAmt;
                that.remark = res.result.remark;
                that.type = res.result.proType;
              }
            });
        },
      });
    },
    comfir() {
      this.$store.commit(
        `${this.type1 == "0" ? "addProduct" : "returnProduct"}`,
        {
          // 货号
          proId: this.proName,
          // 数量
          orderNum: +this.proNum,
          // 单价
          price: this.proPrice,
          // 金额
          realPrice: +this.proPrice * +this.proNum,
          // 备注
          remark: this.remark,
          // 类型
          proType: this.type,
        }
      );
      uni.showToast({
        title: "添加成功",
        icon: "none",
      });
      uni.navigateBack({
        delta: 1,
      });
    },
  },
  onLoad(option) {
    console.log(option.type);
    this.mid = this.$store.state.mid;
    this.type1 = option.type;
  },
};
</script>

<style lang="scss" scoped>
page {
  background: #fff;
}
.scanCode {
  background: #fff;
  height: 100vh;
  padding-top: 50rpx;
  .header_btn {
    display: flex;
    justify-content: space-around;
    align-items: center;
    // margin: 43rpx 52rpx;
    view {
      width: 278rpx;
      height: 85rpx;
      background: #fe3430;
      border-radius: 43rpx;
      color: #fff;
      text-align: center;
      line-height: 85rpx;
    }
    .gray {
      background: #adadad;
    }
  }
  .main {
    width: 717rpx;
    height: 253rpx;
    background: #f1f1f1;
    border-radius: 20rpx;
    margin: 43rpx 17rpx 468rpx 17rpx;
  }
  .footer_btn {
    display: flex;
    justify-content: space-around;
    align-items: center;
    margin: 43rpx 52rpx;
    view {
      width: 278rpx;
      height: 100rpx;
      background: url("/static/images/login/button.png");
      background-size: 278rpx 100rpx;
      border-radius: 43rpx;
      color: #fff;
      text-align: center;
      line-height: 85rpx;
    }
  }
}
</style>
